//
//  WyEngineering.m
//  WY_Read
//
//  Created by wangyang on 2019/11/6.
//  Copyright © 2019 wangyang. All rights reserved.
//

#import "WyEngineering.h"

@interface WyEngineering()

@property (nonatomic, strong)NSUserDefaults *userDefaults;

@end

@implementation WyEngineering
#pragma mark -
#pragma mark - Singleton User
- (NSUserDefaults *)userDefaults {
    if (!_userDefaults) {
        _userDefaults = [NSUserDefaults standardUserDefaults];
    }
    return _userDefaults;
}

+ (WyEngineering *)sharedUser {
    static WyEngineering *sharedUserInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedUserInstance = [[WyEngineering alloc] init];
    });
    return sharedUserInstance;
}

#pragma mark -
#pragma mark Property Setter And Getter
-(NSString *)user_phone{
    return [self.userDefaults objectForKey:@"phone"];
}

-(void)setUser_phone:(NSString *)user_phone{
    [self.userDefaults setObject:user_phone forKey:@"phone"];
}

-(NSString *)user_name{
    return [self.userDefaults objectForKey:@"name"];
}

-(void)setUser_name:(NSString *)user_name{
    [self.userDefaults setObject:user_name forKey:@"name"];
}

-(NSString *)user_nameImage{
    return [self.userDefaults objectForKey:@"nameImage"];
}

- (void)setUser_nameImage:(NSString *)user_nameImage{
    [self.userDefaults setObject:user_nameImage forKey:@"nameImage"];
}



- (BOOL)isLogin {
    
    return self.user_phone ? YES : NO;
}

- (BOOL )logout {
    
    //    NSDictionary *dictionary = [self.userDefaults dictionaryRepresentation];
    //    for(NSString *key in [dictionary allKeys]){
    //        [self.userDefaults removeObjectForKey:key];
    //    }
    //    [self.userDefaults synchronize];
    [self.userDefaults removeObjectForKey:@"phone"];
    
    if (self.user_phone.length <= 0) {
        return YES;
    }else{
        return NO;
    }
    
}
@end
